<template>
  <div class="container">
    <!-- 我的 头部-->
    <div class="header background padding-24 space-between">
      <div class="h-back" @click="goBack">
        <img :src="back" alt />
      </div>
      <div class="title">{{title}}</div>
      <div class="h-right">
        <img :src="play" alt />
      </div>
    </div>
    <!-- 支持的参赛者列表 -->
    <div class="match-list" v-if="contestentList && contestentList.length != 0">
      <div
        class="ml-item"
        v-for="(item,index) in contestentList"
        :key="index"
        @click="toMatchDetail(item.enter_activity_id)"
      >
        <div class="img">
          <img :src="item.user_avator" alt />
          <span class="mine fs-28" v-show="item.self == 1">我</span>
        </div>
        <div class="center">
          <div class="name fs-28">{{item.number}}.{{item.name}}</div>
          <div class="flower fs-24">{{item.vote_num}}鲜花</div>
        </div>
        <div class="bottom">
          <div class="area fs-24">{{item.game_area}}</div>
          <div class="btn fs-28" @click.stop="showModel(item.audition_activity_vote_time_id,item.enter_activity_id)">送花</div>
          <!-- <div class="btns fs-28">送花</div> -->
        </div>
      </div>
    </div>
    <!-- 送花模态框 -->
    <div class="model" v-show="isShowModel" @touchmove.prevent @click.stop="closeFlowerModel">
      <div class="main-mes" @click.stop="mainValue">
        <div class="flower">
          <input
            type="number"
            placeholder="请输入送花数量"
            oninput="value=value.replace(/[^\d]/g,'')"
            v-model="sendNum"
          />
          <span class="fs-32">支</span>
        </div>
        <div class="flower-num fs-32">
          您当前拥有
          <span>{{flowerMes.num}}</span>
          支鲜花
        </div>
        <div class="flower-btn" v-show="!isFree">
          <div class="pay fs-32" @click="buyFlower()">购买鲜花</div>
          <div class="send fs-32" v-show="flowerMes.num != 0" @click="sendFolwer()">送花</div>
          <div class="send active fs-32" v-show="flowerMes.num == 0">送花</div>
        </div>
        <div class="flower-btn-s fs-32" v-show="isFree">送花</div>
        <div class="close-btn" @click="closeFlowerModel">
          <img :src="closeModel" alt />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "my-support",
  data() {
    return {
      id: 0, //活动id
      title: "支持的参赛者",
      back: require("@/assets/index/back-mine.png"),
      play: require("@/assets/index/play-mine.png"),
      closeModel: require("@/assets/index/close-btn.png"),
      flowerMes: {
        num: 8
      },
      isFree: false, //不是免费
      sendNum: null, //送花的数量
      isShowModel: false, //送花model的显示和隐藏
      contestentList: [] //参赛者列表数据
    };
  },
  components: {},
  methods: {
    // 获取我所拥有的鲜花数量
    getFlowerNumber() {
      const url =
        this.$host1 +
        `home/audition/flowerNum?audition_activity_vote_time_id=` +
        this.id;
      this.$axios
        .get(url)
        .then(res => {
          console.log(res.data.data, "---res.data.data--");
          if (res.data.code == 200) {
            this.flowerMes.num = res.data.data.flower_num;
          } else {
            this.AlertWin(res.data.message);
          }
        })
        .catch(err => {
          console.log(err, "err-----");
        });
    },
    // 去参赛者详情页面
    toMatchDetail(id) {
      this.$router.push({
        path: "/index/match-detail",
        query: { id: id, activityId: this.id }
      });
    },
    // 获取我支持的活动数据
    getMySupportData() {
      const url = this.$host1 + `home/audition/myVotedPerson`;
      this.$axios
        .get(url)
        .then(res => {
          // console.log(res.data, "---res.data--");
          if (res.data.code == 200) {
            this.contestentList = res.data.data.list;
          } else {
            this.AlertWin(res.data.message);
          }
        })
        .catch(err => {
          console.log(err, "err-----");
        });
    },
    // 购买鲜花
    buyFlower() {
      this.$router.push({
        path: "/index/buy-flower",
        query: {}
      });
    },
    // 送花
    sendFolwer() {
      if (this.sendNum == null || this.sendNum == 0) {
        this.AlertWin("请输入正确的鲜花数量");
      } else if (this.sendNum > this.flowerMes.num) {
        this.AlertWin("您所拥有的鲜花数量不足，快去购买吧");
      } else {
        this.sendFlowerFn();
      }
    },
    // 送花接口
    sendFlowerFn() {
      const url = this.$host1 + `home/audition/sendFlower`;
      var params = {
        audition_activity_vote_time_id: this.id,
        enter_activity_id: this.enter_activity_id,
        send_flower_num: this.sendNum
      };
      this.$axios
        .post(url, params)
        .then(res => {
          console.log(res.data.data, "---res.data.data--");
          if (res.data.code == 200) {
            this.sendNum = null;
            this.closeFlowerModel();
          } else {
            this.AlertWin(res.data.message);
          }
        })
        .catch(err => {
          console.log(err, "err-----");
        });
    },
    // 返回上一页
    goBack() {
      this.$router.go(-1);
    },
    // 关掉模态框
    closeFlowerModel() {
      this.isShowModel = false;
      this.getMySupportData(); //获取我支持的活动数据
      this.getFlowerNumber();//获取我所拥有的鲜花数量
    },
    // 打开送花模态框
    showModel(id,userId) {
      this.isShowModel = true;
      this.id = id;
      this.enter_activity_id = userId;
      this.getFlowerNumber(); //获取我所拥有的鲜花数量
    },
    // 解决关掉模态框问题
    mainValue() {}
  },
  created() {
    this.getMySupportData(); //获取我支持的活动数据
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
.container {
  padding-top: 1rem;
  box-sizing: border-box;
  // 头部样式设置
  .header {
    background-color: #f8f8f8;
    .h-back {
      width: 0.15rem;
      height: 0.26rem;
      img {
        width: 100%;
      }
    }
    .title {
      font-size: 0.36rem;
      font-weight: bold;
      color: #444444;
    }
    .h-right {
      width: 0.38rem;
      height: 0.5rem;
      img {
        display: inline-block;
        width: 100%;
      }
    }
  }
  .match-list {
    padding: 0.24rem 0.1rem 0.22rem 0.24rem;
    box-sizing: border-box;
    display: flex;
    flex-wrap: wrap;
    background-color: #f5f5f5;
    .ml-item {
      width: 3.42rem;
      height: 6rem;
      margin-right: 0.16rem;
      margin-bottom: 0.24rem;
      background-color: #fff;
      .img {
        position: relative;
        width: 100%;
        height: 4.4rem;
        margin-bottom: 0.2rem;
        border-radius: 0.06rem;
        overflow: hidden;
        img {
          width: 100%;
          height: 100%;
          object-fit: cover;
        }
        .mine {
          position: absolute;
          left: 0;
          top: 0;
          width: 0.48rem;
          height: 0.48rem;
          background: rgba(84, 4, 120, 1);
          font-weight: bold;
          color: rgba(255, 255, 255, 1);
          text-align: center;
          line-height: 0.48rem;
          border-radius: 0.06rem;
        }
      }
      .center {
        display: flex;
        justify-content: space-between;
        padding: 0 0.18rem;
        box-sizing: border-box;
        margin-bottom: 0.25rem;
        .name {
          width: 1.6rem;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          font-weight: 500;
          color: rgba(68, 68, 68, 1);
        }
        .flower {
          font-weight: bold;
          color: rgba(244, 67, 73, 1);
        }
      }
      .bottom {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 0.18rem;
        box-sizing: border-box;
        .area {
          font-weight: 500;
          color: rgba(68, 68, 68, 1);
        }
        .btn,
        .btns {
          width: 1.12rem;
          height: 0.46rem;
          line-height: 0.5rem;
          border-radius: 0.06rem;
          background: rgba(244, 67, 73, 1);
          text-align: center;
          font-weight: 500;
          color: rgba(255, 255, 255, 1);
        }
        .btns {
          background: rgba(221, 221, 221, 1);
          color: #444;
        }
      }
    }
  }

  // 模态框样式设置
  .model {
    width: 100%;
    height: 100vh;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    .main-mes {
      width: 6.77rem;
      height: 4.6rem;
      background-color: #fff;
      position: absolute;
      left: 50%;
      top: 25%;
      transform: translate(-50%);
      padding: 0.7rem 0.4rem 0;
      border-radius: 0.08rem;
      box-sizing: border-box;
      .flower {
        position: relative;
        margin-bottom: 0.43rem;
        input {
          width: 5.98rem;
          height: 0.88rem;
          border: 0.01rem solid rgba(153, 153, 153, 1);
          border-radius: 0.06rem;
          text-indent: 0.26rem;
        }
        input::-webkit-input-placeholder {
          font-size: 0.32rem;
          font-weight: 500;
          color: rgba(153, 153, 153, 1);
        }
        span {
          position: absolute;
          right: 0.26rem;
          top: 0.25rem;
          font-weight: 500;
          color: rgba(68, 68, 68, 1);
        }
      }

      .flower-num {
        font-weight: 500;
        color: rgba(68, 68, 68, 1);
        line-height: 0.32rem;
        margin-bottom: 0.79rem;
        span {
          color: #f44349;
        }
      }

      .flower-btn {
        display: flex;
        justify-content: space-between;
        .pay,
        .send {
          width: 2.84rem;
          height: 0.84rem;
          background: rgba(244, 67, 73, 1);
          border-radius: 0.06rem;
          text-align: center;
          line-height: 0.84rem;
          font-weight: bold;
          color: rgba(255, 255, 255, 1);
        }
        .active {
          background: rgba(245, 245, 245, 1);
          color: #444;
        }
      }
      .flower-btn-s {
        width: 100%;
        height: 0.84rem;
        background: rgba(244, 67, 73, 1);
        border-radius: 0.06rem;
        text-align: center;
        line-height: 0.84rem;
        font-weight: bold;
        color: rgba(255, 255, 255, 1);
      }
      .close-btn {
        width: 0.97rem;
        height: 0.97rem;
        position: absolute;
        bottom: -1.72rem;
        left: 50%;
        transform: translate(-50%);
        img {
          width: 100%;
        }
      }
    }
  }
}
</style>
